from threading import Thread,Lock
from time import sleep


class Account:
    def __init__(self,money,name):
        self.money = money
        self.name = name


#模拟提款操作
class Drawing(Thread):
    def __init__(self,drawing_money,account):
        Thread.__init__(self)
        self.drawing_money = drawing_money
        self.account = account
        self.total  = 0

    def run(self):
        lock1.acquire()
        if self.account.money - self.drawing_money < 0:
            return
        sleep(1)
        #先取钱
        self.account.money -= self.drawing_money
        self.total += self.drawing_money
        lock1.release()
        print(f'{self.name}取了{self.drawing_money}元，还剩{self.account.money}元')

if __name__ == '__main__':
    a1 = Account(100,'zs')
    lock1 = Lock()
    draw1 = Drawing(80,a1)
    draw2 = Drawing(80,a1)
    draw1.start()
    draw2.start()


